import 'package:flutter/material.dart';
import 'model/post.dart';

void main() => runApp(App());

class App extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
      theme: ThemeData(
        primarySwatch: Colors.green
      ),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("前端课程预览"),
      ),
      body: ListView.builder(
        itemCount: posts.length,
        itemBuilder: _listItemBuilder
      ),
      backgroundColor: Colors.grey[100],
    );
  }

  Widget _listItemBuilder(BuildContext context, int index) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.all(10.0),
      child: Column(children: <Widget>[
        Image(image: AssetImage(posts[index].imageUrl)),
        SizedBox(height: 16.0,),
        Text(
          posts[index].title,
          style: TextStyle(
            fontSize: 24.0,
            fontWeight: FontWeight.w500
          ),
        ),
        SizedBox(height: 8.0,),
        Text(
          posts[index].author,
          style: TextStyle(
            fontSize: 16.0
          ),
        ),
        SizedBox(height: 8.0,),
      ],)
    ); 
  }
}

class HelloText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Text(
          "Hello",
          textDirection: TextDirection.ltr,
          style: TextStyle(
            fontSize: 40.0,
            fontWeight: FontWeight.bold,
            color: Colors.green,
          ),
        )
    );
  }
}